<template>
  <div class="students-wrapper page-wrapper">
    <div class="page-title">
      <!-- Students 学生 -->
    </div>
    <div class="container">
      <div class="students-list">
        <h3>Ph.D. Students 博士生</h3>
        <div class="students-container">
          <div class="students-instance" v-for="item in phdStudentsList" :key="item.id">
            <div class="img" :style="`background-image: url('${item.image}')`">
            </div>
            <div class="text">
              <div class="name">{{item.name}}</div>
              <div class="direction">{{item.research_direction}}</div>
              <div class="link" v-if="item.link">
                <el-link :href="item.link" target="_blank" icon="el-icon-user" type="primary">个人主页</el-link>
              </div>
            </div>
          </div>
        </div>
        <h3>Master Students 硕士生</h3>
        <div class="students-container">
          <div class="students-instance" v-for="item in masStudentsList" :key="item.id">
            <div class="img" :style="`background-image: url('${item.image}')`">
            </div>
            <div class="text">
              <div class="name">{{item.name}}</div>
              <div class="direction">{{item.research_direction}}</div>
              <div class="link" v-if="item.link">
                <el-link :href="item.link" target="_blank" icon="el-icon-user" type="primary">个人主页</el-link>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import { RequestStatus } from '../utils/constans';
import { formatBackTime } from '../utils/common';
import { iLabMember } from '../typings/students';
import $api from '../api';

@Component
export default class StudnetsView extends Vue {
  private phdStudentsList: iLabMember[] = [];
  private masStudentsList: iLabMember[] = [];

  private mounted() {
    this.getStudentList();
  }

  private getStudentList() {
    $api.students.findAllLabMembersClient()
    .then((res) => {
      this.phdStudentsList = [];
      this.masStudentsList = [];
      (res as any).map( (record: iLabMember) => {
        // to do
        // record.image = require('../assets/students-1.jpg');
        record.image = 'http://cdn.denghuolife.com/' + record.name + '.jpg?imageMogr2/auto-orient';
        if ( record.educational_level === '博士' ) {
          this.phdStudentsList.push(record);
          console.log(record.image);
        } else if ( record.educational_level === '硕士' ) {
          this.masStudentsList.push(record);
        }
      });
    });
  }
}
</script>

<style lang="scss" scoped>
.students-wrapper{
  padding: 30px;
  .container{
    width: 1200px;
    margin: auto;
  }
  .students-wrapper{
    text-align: left;
  }
  .students-container{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .students-instance{
    width: 31%;
    position: relative;
    margin-bottom: 30px;
    background: white;
    box-sizing: border-box;
    border-right: 2px solid #198afa;
    &:nth-child(3n+2){
      border-color: #f5ae54;
    }
    .img, .text{
      height: 200px;
      display: inline-block;
      vertical-align: top;
    }
    .img{
      position: absolute;
      top: 0;
      left: 0;
      width: 150px;
      background-size: cover;
      background-position: center center;
    }
    .text{
      padding-left: 170px;
      padding-right: 20px;
      .name{
        font-size: 18px;
        font-weight: bold;
        color: #113f6c;
        margin-top: 20px;
      }
      .direction{
        margin-top: 10px;
      }
      .link {
        position: absolute;
        bottom: 10px;
        right: 10px;
      }
    }
  }
}
@media screen and (max-width: 1200px){
    .students-wrapper{
      .students-instance{
        width: 48%;
        &:nth-child(3n+2){
          border-color: #198afa;
        }
        &:nth-child(2n+1){
          border-color: #f5ae54;
        }
      }
    }
}
@media screen and (max-width: 640px){
  .students-wrapper{
      .students-instance{
          width: 49%;
         .img, .text{
            height: 160px;
          }
          .img{
            width: 120px;
          }
          .text{
            padding-left: 130px;
            padding-right: 10px;
          }
      }
  }
}
</style>